--@author Oleg Mayevskiy <mayevskiy.oleg@googlemail.com> (233197)




	table.empty=function(t)
		return 0==table.getn(t)
	end
	-------------------------------
	-- INTERNAL HELFER FUNCTIONS --
	-------------------------------
	-- 			BEGIN 			 --
	-------------------------------

	function _isActive(r)
		return rawget(r,'_active')
	end

	function _peekActiveRoleObject(roles)
		if(isNil(roles)) then
			return nil
		end

		local i = table.getn(roles)
		while(i>0 and not _isActive(roles[i])) do
			i = i-1
		end

		if(0==i) then
			return nil
		else
			return roles[i]
		end
	end

	function _fieldExists(k,c)
		if(not isClass(c)) then
			ierror('trying to check if field exists on a non class variable')
		elseif(not isString(k)) then
			ierror('field name must be of type string')
		end
		if(not isNil(fields(c)) and not isNil(fields(c)[k])) then
			return true, c
		elseif( not isNil(_super(c)) ) then
			return _fieldExists(k,_super(c))
		else
			return false, nil
		end
	end

	function _methodExists(k,c)
		if(not isClass(c)) then
			ierror('trying to check if method exists on a non class variable')
		elseif(not isString(k)) then
			ierror('method name must be of type string')
		end
		if(not isNil(methods(c)) and not isNil(methods(c)[k])) then
			return true, c
		elseif( not isNil(_super(c)) ) then
			return _methodExists(k,_super(c))
		else
			return false, nil
		end
	end

	function printd(...)
		if _debug then
			print('#DEBUG# ', unpack(arg))
		end
	end

	function printdd(...)
		if _ddebug then
			print('#DEBUG FINE# ', unpack(arg))
		end
	end


	function printddd(...)
		if _dddebug then
			print('#DEBUG FINER# ', unpack(arg))
		end
	end


	function printTable(t)
		print("#printTable#")
		if(t) then
			for k,v in pairs(t) do print(k,type(v),v) end
		end
		print("############")
	end

	function ierror(err)
		error('INTERNAL ERROR: '..err)
	end

	function isNil(v)
		if(type(v)=='nil') then
			return true
		else
			return false
		end
	end

	function isTable(t)
		if(type(t)=='table') then
			return true
		else
			return false
		end
	end

	function isNumber(n)
		return type(n)=='number'
	end

	function isString(s)
		return type(s)=='string'
	end

	function isFunction(f)
		if(type(f)=='function') then
			return true
		else
			return false
		end
	end


	function _super(c)
		return rawget(c,'_super')
	end

	function class(o)
		return rawget(o,'_class')
	end

	function fields(t)
		return rawget(t,'_fields')
	end

	function methods(t)
		return rawget(t,'_methods')
	end

	function isObject(o)
		return isTable(o) and not isNil(class(o))
	end

	function isClass(c)
		if(isTable(c) and not isNil(rawget(c,'_isClass')) and rawget(c,'_isClass')==true) then
			return true
		else
			return false
		end
	end

	function isRole(r)
		if(isTable(r) and not isNil(rawget(r,'_isRole')) and rawget(r,'_isRole')==true) then
			return true
		else
			return false
		end
	end

	function isCompatible(c1,c2)
		if( not isClass(c1) ) then
			ierror('c1 is of type '..type(c1)..' but should be a class')
		elseif( not isClass(c2) ) then
			ierror('c2 is of type '..type(c1)..' but should be a class')
		elseif( c1==c2) then
			return true
		elseif( not isNil(_super(c2)) ) then
			return  isCompatible( c1,_super(c2) )
		else
			return false
		end
	end

	function tableCopy(t)
		local tcopy = {}
		for k,v in pairs(t) do
			tcopy[k] = v
		end
		return tcopy
	end

	function tableMerge(t1, t2)
		for k,v in pairs(t2) do
			if isTable(v) then
					if isTable(t1[k] or false) then
							tableMerge(t1[k] or {}, t2[k] or {})
					else
							t1[k] = v
					end
			else
					t1[k] = v
			end
		end
		return t1
	end

	function nameOf(t)
		if(isClass(t) or isRole(t)) then
			return rawget(t,'_name')
		elseif(isNil(t)) then
			ierror('trying to get name, but input is nil')
		else
			ierror('trying to get name on a not class or role variable ')
		end
	end

	function iRoleClassName(roleName)
		return '_role_'..roleName..'_internal_className'
	end

	function _baseClass(r)
		if(not isRole(r)) then
			ierror('trying to read base class on a non role')
		end
		return rawget(r,'_baseClass')
	end

	function _roles(o)
		if(not isObject(o)) then
			ierror('trying to read roles on a non object')
		end
		return rawget(o,'_roles')
	end

	function _role(o)
		return rawget(o,'_role')
	end

	function _roleObject(o)
		return rawget(o,'_roleObject')
	end

	function _baseObject(o)
		local baseObject= rawget(o,'_baseObject')
		if(isNil(baseObject)) then
			ierror('trying to read base object on a non role object')
		else
			return baseObject
		end
	end

	function isRoleObject(o)
		return not isNil(rawget(o,'_baseObject'))
	end

	-------------------------------
	-- INTERNAL HELFER FUNCTIONS --
	-------------------------------
	-- 			END 			 --
	-------------------------------
